package com.uniview.service.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.uniview.service.SessionService;

@Service
public class SessionServiceImpl implements SessionService{

	@Override
	public HttpSession getSession() {
		HttpServletRequest request;
		try {
			request = ((ServletRequestAttributes) RequestContextHolder
					.getRequestAttributes()).getRequest();
		} catch (Exception e) {
			return null;
		}
		return request.getSession();
	}

	@Override
	public void setAttribute(String key, Object val) {
		getSession().setAttribute(key, val);
		
	}

	@Override
	public Object getAttribute(String key) {
		return getSession().getAttribute(key);
	}

	@Override
	public void removeAttribute(String key) {
		getSession().removeAttribute(key);
	}

}
